﻿using System;
using System.Collections.Generic;
using System.Text;
using rkShared.Serialization;
using rkShared.BEncode;

namespace rkShared.Net
{
    [Serializable]
    public class GameInfo : IBinarySerializable
    {
        public string Name { get; set; }
        public int Seed { get; set; }
        public Guid ServerID { get; set; }

        #region IBinarySerializable Members

        /// <summary>
        /// Serializes GameInfo object into a BEncoded Dictrionary
        /// </summary>
        /// <param name="dictionary"></param>
        public void SerializeToDictionary(rkShared.BEncode.BEncodedDictionary dictionary)
        {
            dictionary.Add("n", new BEncodedString(this.Name, true));
            dictionary.Add("s", (BEncodedInt)this.Seed);
            dictionary.Add("sid", (BEncodedString)this.ServerID.ToString());
        }
        public void DeserializeFromDictionary(rkShared.BEncode.BEncodedDictionary dict)
        {
            this.Name = (dict["n"] as BEncodedString).ToString(Encoding.Unicode);
            this.Seed = (BEncodedInt)dict["s"];
            this.ServerID = new Guid(((BEncodedString)dict["sid"]).ToString());
        }

        #endregion
    }
}
